import React, { Component } from 'react';
import { Form, Button, Input } from 'antd-mobile'
import { login } from '../../api'
class Index extends Component {
	handleSubmit = async (value) => {
		const resp = await login(value)
		if (resp.data.code === 200) {
			localStorage.setItem('token', resp.data.token)
			this.props.history.goBack()
		} else {
			alert(resp.data.mess)
		}
	}
	render() {
		return (
			<div>
				<Form
					onFinish={this.handleSubmit}
					layout='horizontal'
					footer={
						<Button block type='submit' color='primary'>
							提交
						</Button>
					}
				>
					<Form.Item
						name='username'
						label='用户名'
						rules={[{ required: true, message: '姓名不能为空' }]}
					>
						<Input onChange={console.log} placeholder='请输入用户名' />
					</Form.Item>
					<Form.Item name='password' label='密码'>
						<Input placeholder='请输入密码' type="password" />
					</Form.Item>
				</Form>
			</div>
		);
	}
}

export default Index;
